use Test::More 'no_plan';

use lib "../lib/cpp", "../lib/ioc", "../lib/toolkit", '../lib/message';

use TinyMessage;
use Signature;

use CHeaderParser;
use CProject;
use CConstructorMatcher;
use CCodeGenerator;
use FindBin;

use IProject;
use IModule;
use IProvider;
use ICreator;

use TestHelper;

my $source = "$FindBin::Bin/cpp/test-creator-1/";
my $out = $source . "generated";

my $iproject = new IProject();
$iproject->load(new CProject($source));

my @modules = @{ $iproject->modules() };

my $module = $iproject->module('Module::AppModule2');
ok($module);

my $moduleClasses = $module->moduleClasses();

is($moduleClasses->keys(), 2);

ok($moduleClasses->exists('Log::STDLogger'));
ok($moduleClasses->exists('Service::GreetingService'));
#ok($moduleClasses->exists('SINGLETON< Log::STDLogger >'));
#ok($moduleClasses->exists('SINGLETON< Service::GreetingService >'));

my $creator = undef;

{
	$provider = $module->class_provider('Log::Logger');
	ok($provider);
	is_deeply($provider, 'getLogger')
}

{
	$creator = $module->class_creator('Log::STDLogger');
	ok($creator);
	is(signature($creator->class()->to_carg('*')), 'Log::STDLogger*');
	is(stringfy($creator->class()), 'Log__STDLogger');
	is($creator->ctor()->count(), 0);
}

{
	$creator = $module->class_creator('Service::GreetingService');
	ok($creator);
	is(signature($creator->class()->to_carg('*')), 'Service::GreetingService*');
	is(stringfy($creator->class()), 'Service__GreetingService');
	is($creator->ctor()->count(), 1);
	is(signature($creator->ctor()->arg(0)), 'Log::Logger*');
}


#{
#	$creator = $module->class_creator('SINGLETON< Service::GreetingService >');
#	ok($creator);
#	is(signature($creator->class()->to_carg('*')), 'SINGLETON< Service::GreetingService >*');
#	is(stringfy($creator->class()), 'SINGLETON_lt_Service__GreetingService_gt_');
#	is($creator->ctor()->count(), 0);
#}

is_deeply($module->includes_rel($out), ['../source/AppModule2.h', '../source/GreetingService.h', '../source/Logger.h']);
is_deeply($module->providers(), [
	new IProvider( 
		class_sig('Log::Logger', []),  
		class_sig('Log::STDLogger', []), 
		'getLogger', 's',
		class_sig('SINGLETON< Log::STDLogger >', []) ),
	new IProvider( 
		class_sig('Service::GreetingService', []),  
		class_sig('Service::GreetingService', []), 
		'getGreetingService', 's',
		class_sig('SINGLETON< Service::GreetingService >', []) )]);
		
CCodeGenerator::generate($module, $out);
isSame($out . "/Module__AppModule2.cpp", $out . "/Module__AppModule2.real");
